package com.mfm;


import java.util.Comparator;

/**
 * @Auther: MFM
 * @Date: 2022/2/27 - 02 - 27 - 20:31
 * @version: 1.0
 */

public class LambdaTest {

    public void test1(){

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("r1");
            }
        };

        r1.run();

        System.out.println("*****************");

        Runnable r2 = () -> System.out.println("r2");

        r2.run();
    }

    public void test2(){

        Comparator<Integer> c = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };

        System.out.println(c.compare(2,3));

        System.out.println("******************");

        //lambda表达式
        Comparator<Integer> c2 = (o1,o2) -> Integer.compare(o1,o2);

        System.out.println(c2.compare(3,2));

        System.out.println("******************");
        //方法引用
        Comparator<Integer> c3 = Integer :: compare;

        System.out.println(c3.compare(2,3));

    }

    public static void main(String[] args) {
        new LambdaTest().test2();
    }
}
